package com.nymph.binding;

import com.nymph.mapping.MappedStatement;
import com.nymph.session.SqlSession;
import org.omg.CORBA.UShortSeqHelper;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: This is a sample class.
 * @Author: Simon
 */
public class MapperRegistry {

    // 一个mapper对应一个mapper-proxy
    private final Map<Class<?>,MapperProxyFactory<?>> knownMappers=new HashMap<>();

    public <T> void addMapper(Class<T> type){
        this.knownMappers.put(type,new MapperProxyFactory<T>(type));
    }

    @SuppressWarnings("unchecked")
    public <T> T getMapper(Class<T> type, SqlSession sqlSession){
        MapperProxyFactory<T> mapperProxyFactory=(MapperProxyFactory<T>) this.knownMappers.get(type);
        return mapperProxyFactory.newInstance(sqlSession);
    }



}
